package com.isay.frameworklib.utils;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import com.isay.frameworklib.application.ApplicationUtils;


public class PreferencesUtils {

    private static SharedPreferences mSharePreferences;
    private static final String CONFIG_FILE_NAME = "share_config";



    private synchronized static SharedPreferences getInstance() {
        if (mSharePreferences == null) {
            Application application = ApplicationUtils.getApplication();
            mSharePreferences = application.getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        }
        return mSharePreferences;
    }

    /**
     * 获取String
     */
    public static String getString(String key, String defValue) {
        return getInstance().getString(key, defValue);
    }


    /**
     * 获取int
     *
     * @param @param key
     * @param @param defValue
     * @return int    返回类型
     * @throws
     * @Title: getInt
     */
    public static int getInt(String key, int defValue) {
        return getInstance().getInt(key, defValue);
    }

    /**
     * 获取long
     *
     * @param @param key
     * @param @param defValue
     * @return long    返回类型
     * @throws
     * @Title: getLong
     */
    public static long getLong(String key, long defValue) {
        return getInstance().getLong(key, defValue);
    }

    /**
     * 获取boolen
     *
     * @param @param key
     * @param @param defValue
     * @return boolean    返回类型
     * @throws
     * @Title: getBoolean
     */
    public static boolean getBoolean(String key, boolean defValue) {
        return getInstance().getBoolean(key, defValue);
    }

    /**
     * 提交 int
     *
     * @param @param key
     * @param @param value
     * @return boolean    返回类型
     * @throws
     * @Title: commit
     */
    public static boolean put(String key, int value) {
        return getInstance().edit().putInt(key, value).commit();
    }

    /**
     * 提交
     */
    public static boolean put(String key, String value) {
        return getInstance().edit().putString(key, value).commit();
    }

    /**
     * commit  long
     *
     * @param @param key
     * @param @param value
     * @return boolean    返回类型
     * @throws
     * @Title: commit
     */
    public static boolean put(String key, long value) {
        return getInstance().edit().putLong(key, value).commit();
    }

    /**
     * 提交boolean
     *
     * @param @param key
     * @param @param value
     * @return boolean    返回类型
     * @throws
     * @Title: commit
     */
    public static boolean put(String key, Boolean value) {
        return getInstance().edit().putBoolean(key, value).commit();
    }

    public static boolean clear(String key) {
        return getInstance().edit().remove(key).commit();
    }

}
